﻿/// <reference path="utils.js" />
'use strict';

define([
    'backbone',
], function (Backbone) {
    var Model = Backbone.Model.extend({
        superClass: null,

        defaults: {
            active: true,
            id: 0,
            description: '',
            name: '',
        },

        constructor: function () {
            this.superClass = Model.__super__;

            this.idAttribute = 'notid',

            this.superClass.constructor.apply(this, arguments);
        },

        set: function (key, val, options) {
            if (key == null) return this;

            var attrs;

            // Handle both `'key', value` and `{key: value}` -style arguments.
            if (typeof key === 'object') {
                attrs = key;
                options = val;
            } else {
                (attrs = {})[key] = val;
            }

            if (!options)
                options = {};

            var activeCurrent = this.get('active'),
                activeNew = attrs.active,
                activeSet = (typeof attrs.active !== 'undefined');

            var activeChanging = ((activeSet == true) && (activeNew != activeCurrent));


            if (activeSet == true)
                attrs.active = (activeNew == true); //To parse it to boolean if it is an int (0/1).


            this.superClass.set.call(this, attrs, options);
        },
    });

    return Model;
});